package com.spzx.product.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.spzx.domain.Brand;
import com.spzx.domain.OrderInfo;
import com.spzx.product.service.IBrandService;
import com.spzx.vo.Result;
import com.spzx.vo.ResultCodeEnum;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

import static com.github.pagehelper.page.PageMethod.startPage;

@Tag(name = "品牌接口管理")
@RestController
@RequestMapping("/brand")
public class BrandController{

    @Autowired
    private IBrandService brandService;


    @Operation(summary = "新增品牌")
    @PostMapping
    public Result add(@RequestBody Brand brand) {
        brandService.add(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "修改品牌")
    @PutMapping
    public Result update(@RequestBody Brand brand) {
        brandService.update(brand);
        return Result.build(null, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "获取品牌详细信息")
    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        Brand brand = brandService.getInfo(id);
        return Result.build(brand, ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询品牌列表")
    @GetMapping("/selectAll`")
    public Result list() {
        List<Brand> list = brandService.list();
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "查询品牌分页")
    @GetMapping("/findPage/{page}/{limit}")
    public Result listPage(@PathVariable Integer page,@PathVariable Integer limit,@RequestBody Brand brand) {
        Page<Brand> pageParam = new Page<>(page, limit);
        IPage<Brand> list = brandService.listPage(pageParam, brand);
        return Result.build(list,ResultCodeEnum.SUCCESS);
    }

    @Operation(summary = "删除品牌")
    @DeleteMapping("/{ids}")
    public Result remove(@PathVariable Long[] ids) {
        brandService.deleteBrandByIds(ids);
        return Result.build(null,ResultCodeEnum.SUCCESS);
    }
}
